package com.medicalsys.platform.controller;

import com.medicalsys.platform.bean.User;
import com.medicalsys.platform.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/*
用户响应层
 */
@Controller
public class UserController {
    @Autowired
    private UserService userService;

    //登录
    @PostMapping("/loginpost")
    @ResponseBody
    public String login(String account, String password, HttpServletRequest request){
        return userService.login(account, password, request.getSession());
    }

    //注册
    @PostMapping("/registpost")
    @ResponseBody
    public String regist(String account,String password,String type){
       return userService.insertUser(account, password,type);
    }

    //导航页变化
    @GetMapping("/data/navs.json")
    @ResponseBody
    public String type(HttpServletRequest request){
        HttpSession session = request.getSession();
        User user= (User) session.getAttribute("user");
        if(user.getType().equals("doctors")){
            return "[\n" +
                    "  {\n" +
                    "    \"title\": \"首页\",\n" +
                    "    \"href\": \"/index\",\n" +
                    "    \"fontFamily\": \"ok-icon\",\n" +
                    "    \"icon\": \"&#xe6bb;\",\n" +
                    "    \"spread\": true,\n" +
                    "    \"isCheck\": true\n" +
                    "  },\n" +
                    "  {\n" +
                    "    \"title\": \"病人诊疗\",\n" +
                    "    \"href\": \"/tonpatient/list\",\n" +
                    "    \"icon\": \"&#xe66f;\",\n" +
                    "    \"spread\": false\n" +
                    "  },\n" +
                    "  {\n" +
                    "    \"title\": \"诊疗记录\",\n" +
                    "    \"href\": \"/mdfile/list\",\n" +
                    "    \"fontFamily\": \"ok-icon\",\n" +
                    "    \"icon\": \"&#xe739;\",\n" +
                    "    \"spread\": false\n" +
                    "  },\n" +
                    "  {\n" +
                    "    \"title\": \"医案库\",\n" +
                    "    \"href\": \"/famouns/recordlist\",\n" +
                    "    \"icon\": \"&#xe705;\",\n" +
                    "    \"spread\": false\n" +
                    "  },\n" +
                    "  {\n" +
                    "    \"title\": \"中药库\",\n" +
                    "    \"href\": \"/drug/list\",\n" +
                    "    \"icon\": \"&#xe62e;\",\n" +
                    "    \"spread\": false\n" +
                    "  },\n" +
                    "  {\n" +
                    "    \"title\": \"远程问诊\",\n" +
                    "    \"href\": \"\",\n" +
                    "    \"fontFamily\": \"ok-icon\",\n" +
                    "    \"icon\": \"&#xe6be;\",\n" +
                    "    \"spread\": false,\n" +
                    "    \"children\": [\n" +
                    "      {\n" +
                    "        \"title\": \"视频会话\",\n" +
                    "        \"fontFamily\": \"ok-icon\",\n" +
                    "        \"href\": \"/chat/video\",\n" +
                    "        \"icon\": \"&#xe665;\",\n" +
                    "        \"spread\": false\n" +
                    "      },\n" +
                    "      {\n" +
                    "        \"title\": \"数字数据\",\n" +
                    "        \"fontFamily\": \"ok-icon\",\n" +
                    "        \"href\": \"/chat/data\",\n" +
                    "        \"icon\": \"&#xe6f5;\",\n" +
                    "        \"spread\": false\n" +
                    "      }\n" +
                    "    ]\n" +
                    "  }\n" +
                    "]\n";
        }else{
            return "[\n" +
                    "  {\n" +
                    "    \"title\": \"首页\",\n" +
                    "    \"href\": \"/indexb\",\n" +
                    "    \"fontFamily\": \"ok-icon\",\n" +
                    "    \"icon\": \"&#xe6bb;\",\n" +
                    "    \"spread\": true,\n" +
                    "    \"isCheck\": true\n" +
                    "  },\n" +
                    "  {\n" +
                    "    \"title\": \"远程问诊\",\n" +
                    "    \"href\": \"\",\n" +
                    "    \"fontFamily\": \"ok-icon\",\n" +
                    "    \"icon\": \"&#xe6be;\",\n" +
                    "    \"spread\": false,\n" +
                    "    \"children\": [\n" +
                    "      {\n" +
                    "        \"title\": \"视频会话\",\n" +
                    "        \"fontFamily\": \"ok-icon\",\n" +
                    "        \"href\": \"/chat/videob\",\n" +
                    "        \"icon\": \"&#xe665;\",\n" +
                    "        \"spread\": false\n" +
                    "      },\n" +
                    "      {\n" +
                    "        \"title\": \"数字数据\",\n" +
                    "        \"fontFamily\": \"ok-icon\",\n" +
                    "        \"href\": \"/chat/data\",\n" +
                    "        \"icon\": \"&#xe6f5;\",\n" +
                    "        \"spread\": false\n" +
                    "      }\n" +
                    "    ]\n" +
                    "  }\n" +
                    "]\n";
        }
    }

    //找回密码
    @PostMapping("/forgetpost")
    @ResponseBody
    public String forget(String account,String password){
        return userService.updatePass(account, password);
    }


    //更新用户信息
    @PostMapping("/updateuserinfo")
    @ResponseBody
    public String updateUserInfo(String username,String oldpassword,String password,HttpServletRequest request){
        return userService.updateUser(username, oldpassword,password, request.getSession());
    }
}
